package com.zmc.lostfound.file.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author ZMC
 * @description Swagger2接口测试配置
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {

    /**
     * 配置Swagger的Docket的bean实例
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(this.apiInfo())
                //groupName("xxx"): 配置API文档的分组
                .groupName("file")
                .select()
                /*RequestHandlerSelectors: 用来配置扫描接口的方式
                 * basePackage("xxx"): 指定要扫描的包,最常用
                 * any(): 扫描全部
                 * none(): 不扫描
                 * withMethodAnnotation("xxx"): 扫描作用于方法上的注解，参数是该注解的反射对象
                 * withClassAnnotation("xxx"): 扫描作用于类上的注解，参数是该注解的反射对象
                 */
                .apis(RequestHandlerSelectors.basePackage("com.zmc.lostfound.file.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 配置Swagger的apiInfo,编写Swagger信息
     */
    private ApiInfo apiInfo() {
        //作者信息
        Contact contact = new Contact("张铭铖、魏荐书、郭啸尘、刘锦奇", "https://gitee.com/graduation-training", "2869581855@qq.com");
        return new ApiInfoBuilder()
                .contact(contact)
                //标题
                .title("文件管理服务")
                //描述
                .description("lost-found-file SwaggerAPI文档")
                //版本号
                .version("1.0.0")
                .termsOfServiceUrl("http://localhost:65030/file/doc.html#/home")
                .build();
    }

}
